import routes from "./routes";
import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);
const originPush = VueRouter.prototype.push;
const originReplace = VueRouter.prototype.replace;
VueRouter.prototype.push = function (location, okCallBack, errCallBack) {
  if (okCallBack === undefined && errCallBack === undefined) {
    originPush.call(this, location).catch(() => {});
  } else {
    originPush.call(this, location, okCallBack, errCallBack);
  }
};
const router = new VueRouter({
  routes,
});
VueRouter.prototype.replace = function (location, okCallBack, errCallBack) {
  if (okCallBack === undefined && errCallBack === undefined) {
    // 上面的判断成立的话，表示没有传递这两个参数
    originReplace.call(this, location).catch(() => {}); // 统一处理报错的问题 一劳永逸
  } else {
    originReplace.call(this, location, okCallBack, errCallBack);
  }
};

export default router;
